package Examples;

import guiTesting.RetrieveUserInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.AbstractTableModel;

import com.atlassian.crowd.exception.ApplicationPermissionException;
import com.atlassian.crowd.exception.InvalidAuthenticationException;
import com.atlassian.crowd.exception.OperationFailedException;
import com.atlassian.crowd.model.user.User;

public class DefaultTableModel extends AbstractTableModel {

	public  String[] columnNames = {"First Name ", "Last Name","Email" , "Display Name", "Is Active"};
	private List<User>  rowData;
	DefaultTableModel model; 

	public  DefaultTableModel(List rowData, String []columnNames ){
		this.rowData = rowData; 
		this.columnNames=columnNames; 
	}


	//get column counts 
	public int getColumnCount() {
		return columnNames.length;
	}

	//get row counts 
	public int getRowCount() {
		return  rowData.size();
	}

	public String  getColumnName(int col){
		return columnNames[col];

	}

	//since table is displaying results no editing needed 
	public boolean isCellEditable(int row, int col) {  
		return false;
	}
	public void setValueAt(Object value, int rowIndex, int columnIndex) {
		ArrayList l = (ArrayList) rowData.get(rowIndex); 
		for (int i=0; i<l.size(); i++){
			value = l.get(i); 
			rowData.set(rowIndex, (User) value); 
		}
		
		
		//getRecord(rowIndex)[columnIndex] = value;
		super.fireTableCellUpdated(rowIndex, columnIndex);
		System.out.println(value); 
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		Vector g =  (Vector) rowData.get(rowIndex); 
		Object k = null ; 
		for (int j =0; j<g.size(); j++){
			k = g;
		}
		System.out.println("Iam getting value");
		System.out.println(rowData.get(rowIndex));
		return k ; //   rowData.get(rowIndex) ;  // getRecord(rowIndex)[columnIndex];
	}

	

}
